//打开页面
Vue.prototype.openPage = function (path, id, params) {
    // let queryParam = {id: id, parent: this.$route.path};
    let queryParam = {id: id};
    if (params) {
        for (let key in params) {
            queryParam[key] = params[key];
        }
    }
    this.$router.push({path: path, query: queryParam});
};
//关闭页面
Vue.prototype.closePage = function (path) {
    if(!path) {
        path = this.$route.fullPath;
    }
    this.$emit('close-page',path)
};

//图标列表
Vue.prototype.iconList = ['icon-home','icon-home-fill','icon-calculator', 'icon-prepare', 'icon-set', 'icon-plan'
    , 'icon-ruler', 'icon-build', 'icon-ananalysis', 'icon-evaluate'
    , 'icon-card', 'icon-contract', 'icon-mark'
    , 'icon-container', 'iconfont icon-icon', 'iconfont icon-jihua'
    , 'iconfont icon-daiban', 'iconfont icon-xitongpeizhi', 'iconfont icon-hetong'
    , 'iconfont icon-jindu', 'iconfont icon-dengjizongshu', 'iconfont icon-qiapianshuliang'
    , 'iconfont icon-4-feiyong', 'iconfont icon-3-tingyong', 'iconfont icon-2-weixiu'
    , 'iconfont icon-1-shebei', 'iconfont icon-4-zong', 'iconfont icon-5-yixia'
    , 'iconfont icon-icon-project', 'iconfont icon-4-zong', 'iconfont icon-5-yixia'
    ,'iconfont icon-xiangmu','iconfont icon-project','iconfont icon-qian','iconfont icon-qiandai'
    ,'iconfont icon-qianbao','iconfont icon-qiandai1','iconfont icon-2-lieruqianqishu'
    ,'iconfont icon-4-xiangmuzongtouzi','iconfont icon-5-yixiadatouzi','iconfont icon-6-yiwanchengtouzi'
    ,'iconfont icon-8-tongguoxiangmshu','iconfont icon-9-tuihuixiangmshu','iconfont icon-10-zaijianxiangmshu'
    ,'iconfont icon-11-jinduchao80','iconfont icon-12-chaoqi','iconfont icon-13-qianyue','iconfont icon-14-yijiesuane'
    ,'iconfont icon-15-daijiesuan','iconfont icon-zuanjingyusuan','iconfont icon-zigognchegnchaijie'
    ,'iconfont icon-tianxie','iconfont icon-qidongjihua1','iconfont icon-zigongcweihu','iconfont icon-jihuahuizong'
    ,'iconfont icon-shengchanshujuhuizong','iconfont icon-shengchanshujudaoru','iconfont icon-154','iconfont icon-153'
    ,'iconfont icon-152','iconfont icon-151','iconfont icon-145','iconfont icon-144','iconfont icon-143'
    ,'iconfont icon-142','iconfont icon-141','iconfont icon-83','iconfont icon-82','iconfont icon-812','iconfont icon-811'
    ,'iconfont icon-81','iconfont icon-71','iconfont icon-62','iconfont icon-61','iconfont icon-56','iconfont icon-55'
    ,'iconfont icon-54','iconfont icon-53','iconfont icon-52','iconfont icon-51','iconfont icon-47','iconfont icon-46'
    ,'iconfont icon-45','iconfont icon-44','iconfont icon-43','iconfont icon-42','iconfont icon-41'
    ,'iconfont icon-36','iconfont icon-34','iconfont icon-33','iconfont icon-32','iconfont icon-31'
    ,'iconfont icon-designinpu','iconfont icon-27','iconfont icon-253','iconfont icon-251','iconfont icon-252'
    ,'iconfont icon-25','iconfont icon-24','iconfont icon-23','iconfont icon-22','iconfont icon-214'
    ,'iconfont icon-213','iconfont icon-212','iconfont icon-211','iconfont icon-21','iconfont icon-12','iconfont icon-11'
    ,'el-icon-ice-cream-round','el-icon-ice-cream-square','el-icon-lollipop','el-icon-potato-strips'
    ,'el-icon-milk-tea','el-icon-ice-drink','el-icon-ice-tea','el-icon-coffee','el-icon-orange','el-icon-pear'
    ,'el-icon-apple','el-icon-cherry','el-icon-watermelon','el-icon-grape','el-icon-refrigerator'
    ,'el-icon-goblet-square-full','el-icon-goblet-square','el-icon-goblet-full','el-icon-goblet'
    ,'el-icon-cold-drink','el-icon-coffee-cup','el-icon-water-cup','el-icon-hot-water','el-icon-ice-cream'
    ,'el-icon-dessert','el-icon-sugar','el-icon-tableware','el-icon-burger','el-icon-knife-fork','el-icon-fork-spoon'
    ,'el-icon-chicken','el-icon-food','el-icon-dish-1','el-icon-dish','el-icon-moon-night','el-icon-moon'
    ,'el-icon-cloudy-and-sunny','el-icon-partly-cloudy','el-icon-cloudy','el-icon-sunny','el-icon-sunset'
    ,'el-icon-sunrise-1','el-icon-sunrise','el-icon-heavy-rain','el-icon-lightning','el-icon-light-rain'
    ,'el-icon-wind-power','el-icon-baseball','el-icon-soccer','el-icon-football','el-icon-basketball'
    ,'el-icon-ship','el-icon-truck','el-icon-bicycle','el-icon-mobile-phone','el-icon-service','el-icon-key'
    ,'el-icon-unlock','el-icon-lock','el-icon-watch','el-icon-watch-1','el-icon-timer','el-icon-alarm-clock'
    ,'el-icon-map-location','el-icon-delete-location','el-icon-add-location','el-icon-location-information'
    ,'el-icon-location-outline','el-icon-location','el-icon-place','el-icon-discover','el-icon-first-aid-kit'
    ,'el-icon-trophy-1','el-icon-trophy','el-icon-medal','el-icon-medal-1','el-icon-stopwatch','el-icon-mic'
    ,'el-icon-copy-document','el-icon-full-screen','el-icon-switch-button','el-icon-aim','el-icon-crop'
    ,'el-icon-odometer','el-icon-time','el-icon-bangzhu','el-icon-close-notification','el-icon-microphone'
    ,'el-icon-turn-off-microphone','el-icon-position','el-icon-postcard','el-icon-message','el-icon-chat-line-square'
    ,'el-icon-chat-dot-square','el-icon-chat-dot-round','el-icon-chat-square','el-icon-chat-line-round','el-icon-chat-round'
    ,'el-icon-set-up','el-icon-turn-off','el-icon-open','el-icon-connection','el-icon-link','el-icon-cpu'
    ,'el-icon-thumb','el-icon-female','el-icon-male','el-icon-guide','el-icon-news','el-icon-price-tag'
    ,'el-icon-discount','el-icon-wallet','el-icon-coin','el-icon-money','el-icon-bank-card','el-icon-box'
    ,'el-icon-present','el-icon-sell','el-icon-sold-out','el-icon-shopping-bag-2','el-icon-shopping-bag-1'
    ,'el-icon-shopping-cart-2','el-icon-shopping-cart-1','el-icon-shopping-cart-full','el-icon-smoking'
    ,'el-icon-no-smoking','el-icon-house','el-icon-table-lamp','el-icon-school','el-icon-office-building'
    ,'el-icon-toilet-paper','el-icon-notebook-2','el-icon-notebook-1','el-icon-files','el-icon-collection'
    ,'el-icon-receiving','el-icon-suitcase-1','el-icon-suitcase','el-icon-film','el-icon-collection-tag'
    ,'el-icon-data-analysis','el-icon-pie-chart','el-icon-data-board','el-icon-data-line','el-icon-reading'
    ,'el-icon-magic-stick','el-icon-coordinate','el-icon-mouse','el-icon-brush','el-icon-headset','el-icon-umbrella'
    ,'el-icon-scissors','el-icon-mobile','el-icon-attract','el-icon-monitor','el-icon-search','el-icon-takeaway-box'
    ,'el-icon-paperclip','el-icon-printer','el-icon-document-add','el-icon-document','el-icon-document-checked'
    ,'el-icon-document-copy','el-icon-document-delete','el-icon-document-remove','el-icon-tickets'
    ,'el-icon-folder-checked','el-icon-folder-delete','el-icon-folder-remove','el-icon-folder-add'
    ,'el-icon-folder-opened','el-icon-folder','el-icon-edit-outline','el-icon-edit','el-icon-date'
    ,'el-icon-c-scale-to-original','el-icon-view','el-icon-loading','el-icon-rank','el-icon-sort-down'
    ,'el-icon-sort-up','el-icon-sort','el-icon-finished','el-icon-refresh-left','el-icon-refresh-right'
    ,'el-icon-refresh','el-icon-video-play','el-icon-video-pause','el-icon-d-arrow-right'
    ,'el-icon-d-arrow-left','el-icon-arrow-up','el-icon-arrow-down','el-icon-arrow-right','el-icon-arrow-left'
    ,'el-icon-top-right','el-icon-top-left','el-icon-top','el-icon-bottom','el-icon-right','el-icon-back'
    ,'el-icon-bottom-right','el-icon-bottom-left','el-icon-caret-top','el-icon-caret-bottom','el-icon-caret-right'
    ,'el-icon-caret-left','el-icon-d-caret','el-icon-share','el-icon-menu','el-icon-s-grid','el-icon-s-check'
    ,'el-icon-s-data','el-icon-s-opportunity','el-icon-s-custom','el-icon-s-claim','el-icon-s-finance'
    ,'el-icon-s-comment','el-icon-s-flag','el-icon-s-marketing','el-icon-s-shop','el-icon-s-open','el-icon-s-management'
    ,'el-icon-s-ticket','el-icon-s-release','el-icon-s-home','el-icon-s-promotion','el-icon-s-operation'
    ,'el-icon-s-unfold','el-icon-s-fold','el-icon-s-platform','el-icon-s-order','el-icon-s-cooperation'
    ,'el-icon-bell','el-icon-message-solid','el-icon-video-camera','el-icon-video-camera-solid','el-icon-camera'
    ,'el-icon-camera-solid','el-icon-download','el-icon-upload2','el-icon-upload','el-icon-picture-outline-round'
    ,'el-icon-picture-outline','el-icon-picture','el-icon-close','el-icon-check','el-icon-plus','el-icon-minus'
    ,'el-icon-help','el-icon-s-help','el-icon-circle-close','el-icon-circle-check','el-icon-circle-plus-outline'
    ,'el-icon-remove-outline','el-icon-zoom-out','el-icon-zoom-in','el-icon-error','el-icon-success','el-icon-circle-plus'
    ,'el-icon-remove','el-icon-info','el-icon-question','el-icon-warning-outline','el-icon-warning','el-icon-goods'
    ,'el-icon-s-goods','el-icon-star-off','el-icon-star-on','el-icon-more-outline','el-icon-more','el-icon-phone-outline'
    ,'el-icon-phone','el-icon-user','el-icon-user-solid','el-icon-setting','el-icon-s-tools','el-icon-delete'
    ,'el-icon-delete-solid','el-icon-eleme','el-icon-platform-eleme','el-icon-loading'
];
//加载元数据列表
Vue.prototype.loadMetaList = function (type,callback) {
    let url = "/meta/type/"+type;
    this.addAjaxCachePath(url)
    this.$get(url, {}, (response) => {
        callback(response.data);
    },()=>{
    })
}
//加载元数据名称映射集合
Vue.prototype.loadMetaNameMap = function (type,callback) {
    let url = "/meta/type/"+type;
    this.addAjaxCachePath(url)
    this.$get(url, {}, (response) => {
        let map = {};
        for(let item of response.data) {
            map[item.id] = item.name;
        }
        callback(map);
    },()=>{
    })
}
//加载元数据集合
Vue.prototype.loadMetaMap = function (type,callback) {
    let url = "/meta/type/"+type;
    this.addAjaxCachePath(url)
    this.$get(url, {}, (response) => {
        let map = {};
        for(let item of response.data) {
            map[item.id] = item;
        }
        callback(map);
    },()=>{
    })
}

//打开全局遮罩层
Vue.prototype.openLoading = function(text) {
    if(!text) {
        text = '正在处理,请稍后...';
    }
    const loading = this.$loading({ // 声明一个loading对象
        lock: true, // 是否锁屏
        text: text, // 加载动画的文字
        spinner: 'el-icon-loading', // 引入的loading图标
        background: 'rgba(0, 0, 0, 0.7)' // 背景颜色
    })
    return loading;
}

import ECharts from 'vue-echarts'
import { use } from 'echarts/core'

// import ECharts modules manually to reduce bundle size
import {  } from 'echarts/components'
import {
    CanvasRenderer
} from 'echarts/renderers'
import {
    BarChart, PieChart, ScatterChart,EffectScatterChart,LineChart
} from 'echarts/charts'
import {
    GridComponent,
    TooltipComponent,
    TitleComponent,
    LegendComponent,
    MarkLineComponent,
    MarkAreaComponent,
    ToolboxComponent,
    VisualMapComponent,
    BrushComponent,
} from 'echarts/components'

use([
    CanvasRenderer,
    BarChart,PieChart,ScatterChart,EffectScatterChart,LineChart,
    GridComponent,
    TooltipComponent,
    TitleComponent,
    LegendComponent,
    MarkLineComponent,
    MarkAreaComponent,
    ToolboxComponent,
    VisualMapComponent,
    BrushComponent,
]);

// register globally (or you can do it locally)
Vue.component('v-chart', ECharts)
// Vue.component("v-chart", ECharts);

//keep-alive 热部署插件
import VueKeepAliveDev from 'vue-keep-alive-dev'
Vue.use(VueKeepAliveDev, {
    environment: 'dev' // Your environment when HMR is in use
});

import excel from "./excel";
Vue.prototype.exportExcel = (config,fileName)=>{
    excel.exportExcel(config,fileName);
}

/**
 * 验证是否为【数字】，主要用于element rules的validator
 * */
Vue.prototype.validatorNum = function (rule, value, callback) {
    if (value && isNaN(value)) {
        callback(new Error("必须为正确的数字"));
        return false;
    } else {
        callback();
        return true;
    }
}
/**
 * 验证是否为【大于0数字】，主要用于element rules的validator
 * */
Vue.prototype.validatorGatherZeroNum = function (rule, value, callback) {
    if (value && (isNaN(value) || value <= 0)) {
        callback(new Error("必须为大于0的数字"));
        return false;
    } else {
        callback();
        return true;
    }
}
/**
 * 验证是否为【大于或等于0数字】，主要用于element rules的validator
 * */
Vue.prototype.validatorGEZeroNum = function (rule, value, callback) {
    if (value && (isNaN(value) || value < 0)) {
        callback(new Error("必须为大于或等于0的数字"));
        return false;
    } else {
        callback();
        return true;
    }
}
/**
 * 验证是否为【正整数】，主要用于element rules的validator
 * */
Vue.prototype.validatorIntegerNum = function (rule, value, callback) {
    if (value && (isNaN(value) || value % 1 != 0)) {
        callback(new Error("必须为正整数"));
        return false;
    } else {
        callback();
        return true;
    }
}


/**
 * 验证【大于、等于0的数字】（可为空），
 * 主要用于element rules的validator
 */
Vue.prototype.validatorExistNumber = function (rule, value, callback) {
    if (value == null || value == "" || value == undefined || (value && !isNaN(value) && value >= 0)) {
        callback();
        return true;
    } else {
        callback(new Error("必须为正确数字，且不小于0"));
        return false;
    }
}
